package com.ambow.restaurant.sys.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.restaurant.sys.po.Order;
import com.ambow.restaurant.sys.service.IOrderService;
import com.ambow.restaurant.sys.service.OrderServiceIMPL;

/**
 * Servlet implementation class SaleListServlet
 */
@WebServlet("/sys/saleList.do")
public class SaleListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	IOrderService orderService = new OrderServiceIMPL();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SaleListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
    	String method =request.getParameter("method");
    	if(method != null && method.equals("list")) {
    		request.getRequestDispatcher("/jsp/sys/saleList.jsp").forward(request, response);
    		
    	}else if(method != null && method.equals("month")) {
    		List<Order> orderList = orderService.findMonth();
    		request.setAttribute("orders", orderList);
    		request.getRequestDispatcher("/jsp/sys/saleList.jsp").forward(request, response);
    	}else if(method != null && method.equals("week")) {
    		List<Order> orderList = orderService.findWeek();
    		request.setAttribute("orders", orderList);
    		request.getRequestDispatcher("/jsp/sys/saleList.jsp").forward(request, response);
    	}else if(method != null && method.equals("day")) {
    		List<Order> orderList = orderService.findDay();
    		request.setAttribute("orders", orderList);
    		request.getRequestDispatcher("/jsp/sys/saleList.jsp").forward(request, response);
    	}
    	
    }

}
